package com.ocom.ugcapi.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.ocom.common.constant.WxServiceUrl;
import com.ocom.common.dto.GetMealTimeDto;
import com.ocom.common.entity.card.*;
import com.ocom.common.entity.company.EntityCompanyConfig;
import com.ocom.common.entity.human.EntityPersonnelInfo;
import com.ocom.common.entity.payconfig.EntityMealPlan;
import com.ocom.common.entity.payconfig.EntityReceiptAddressPrice;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.GetChangeDishesListRequest;
import com.ocom.common.request.payconfig.GetDishesFormCartRequest;
import com.ocom.common.request.payconfig.RemoveDishesToCartRequest;
import com.ocom.common.request.payconfig.adreceiptinfo.GetAdReceiptInfoRequest;
import com.ocom.common.request.payconfig.mealorder.GetMerchPointListRequest;
import com.ocom.common.request.payconfig.mealorder.GetOrderPlanDishesRequest;
import com.ocom.common.request.payconfig.mealorder.GetOrderPlanDishesResponse;
import com.ocom.common.request.payconfig.mealorder.GetOrderPlanMealRequest;
import com.ocom.common.request.payhandle.GetRecordProcessRequest;
import com.ocom.common.request.payhandle.OrderDishesPayRequest;
import com.ocom.common.request.payhandle.ShoppingCartRequest;
import com.ocom.common.request.ugcapi.GetOrderPlanMealBRequest;
import com.ocom.common.request.ugcapi.OrderMealPlanLoadDishesClassRequest;
import com.ocom.common.request.ugcapi.OrderMealPlanSubmitRequest;
import com.ocom.common.request.ugcapi.UgcOrderedShowRequest;
import com.ocom.common.request.ugcapi.order.LoadRestaurantsRequest;
import com.ocom.common.request.web.ConsTimeConfigOnShowRequest;
import com.ocom.common.request.web.ConsumeLimitConfigOnShowRequest;
import com.ocom.common.request.xfrecde.GetPerVideoListRequest;
import com.ocom.common.request.xfrecde.GetUserOrdered;
import com.ocom.common.request.xfrecde.GetUserOrderedB;
import com.ocom.common.request.xfrecde.UpdateChangeDishesRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.*;
import com.ocom.common.vo.human.UserInfoVo;
import com.ocom.common.vo.pay.CheckVo;
import com.ocom.common.vo.payconfig.GetDishesFormCartVo;
import com.ocom.common.vo.payconfig.OrderPlanMealVo;
import com.ocom.common.vo.ugcapi.*;
import com.ocom.common.vo.webapi.InLimitConfigVo;
import com.ocom.common.vo.webapi.LimitListVo;
import com.ocom.common.vo.webapi.ReConsumeLimitVo;
import com.ocom.common.vo.xfrecode.OrderedMealBVo;
import com.ocom.common.vo.xfrecode.OrderedMealVo;
import com.ocom.ugcapi.client.*;
import com.ocom.ugcapi.mq.product.ActiveQuiryProduct;
import com.ocom.ugcapi.vo.DishesFormCartVo;
import com.ocom.ugcapi.vo.ReceiptAddressVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2023/5/15
 **/
@Slf4j
@RestController
public class OrderMealPlanController {

	@Autowired
	ActiveQuiryProduct activeQuiryProduct;

	@Autowired
	XfRecodeClientService xfRecodeClientService;

	@Autowired
	PayConfigClientService payConfigClientService;

	@Autowired
	PayHandleClientService payHandleClientService;

	@Autowired
	private HumanClientService humanClientService;

	@Autowired
	CompanyClientService companyClientService;


	/**
	 * 6.1加载取餐地点列表（OrderMealPlan/loadReceipt）
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanLoadReceipt)
	public Result loadReceipt(@RequestBody Map<String, Object> map) {
		LoadReceiptVo loadReceiptVo = JSON.parseObject(JSON.toJSONString(map), LoadReceiptVo.class);

		GetAdReceiptInfoRequest request = new GetAdReceiptInfoRequest();
		request.setComId(loadReceiptVo.getUserInfo().getComId());
		request.setReceiptName(loadReceiptVo.getReceiptName());
		request.setPointId(loadReceiptVo.getPointId());
		Result resultA = payConfigClientService.getAdReceiptInfo(request);

		if(!resultA.getCode().equals(200)){
			return resultA;
		}
		EntityReceiptAddressPrice entityReceiptAddressPrice = new EntityReceiptAddressPrice();
		entityReceiptAddressPrice.setComId(request.getComId());
		entityReceiptAddressPrice.setPointId(request.getPointId());
		Result<List<EntityReceiptAddressPrice>> result = payConfigClientService.getReceiptAddressPriceList(entityReceiptAddressPrice);
		List<ReceiptAddressVo> addressList = JSON.parseArray(JSON.toJSONString(resultA.getData()),ReceiptAddressVo.class);
		List<ReceiptAddressVo> resultList = new ArrayList<>();
		Map<Integer,Integer> receiptPrice = new HashMap<>();
		addressList.forEach(entityReceiptAddress -> {
			receiptPrice.put(entityReceiptAddress.getReceiptId(),0);
			result.getData().forEach(receiptAddressPrice->{
				if(	receiptPrice.get(entityReceiptAddress.getReceiptId()).equals(0)){
					entityReceiptAddress.setPrice(0);
				}

				if(
						receiptAddressPrice.getReceiptId().equals(entityReceiptAddress.getReceiptId())
						&& receiptAddressPrice.getPointId().equals(entityReceiptAddress.getPointId())
						&& !receiptAddressPrice.getPointId().equals(0)
						&& receiptAddressPrice.getPrice() > 0
				){
					entityReceiptAddress.setReceiptName(entityReceiptAddress.getReceiptName());
					entityReceiptAddress.setPrice(receiptAddressPrice.getPrice());
					receiptPrice.put(entityReceiptAddress.getReceiptId(),1);
				} else if (
						entityReceiptAddress.getPointId().equals(0)
						&& receiptAddressPrice.getReceiptId().equals(entityReceiptAddress.getReceiptId())
						&& receiptAddressPrice.getPrice() > 0
						&& !receiptPrice.get(entityReceiptAddress.getReceiptId()).equals(1)
				) {
					entityReceiptAddress.setReceiptName(entityReceiptAddress.getReceiptName());
					entityReceiptAddress.setPrice(receiptAddressPrice.getPrice());
					receiptPrice.put(entityReceiptAddress.getReceiptId(),2);
				}
			});
		});
		return ResultUtil.success(addressList);
	}

	/**
	 * 6.2加载商户、消费点列表（OrderMealPlan/loadMerchPoint）
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanLoadMerchPoint)
	public Result loadMerchPoint(@RequestBody Map<String, Object> map) {
		LoadMerchPointVo loadMerchPointVo = JSON.parseObject(JSON.toJSONString(map), LoadMerchPointVo.class);
		GetMerchPointListRequest request = new GetMerchPointListRequest();
		request.setComId(loadMerchPointVo.getUserInfo().getComId());
		request.setMealDate(loadMerchPointVo.getMealDate());
		request.setReceiptId(loadMerchPointVo.getReceiptId());
		return payConfigClientService.getMerchPointList(request);
	}

	/**
	 * 6.3点餐查询（OrderMealPlan/onShow）
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanOnShow)
	public Result onShow(@RequestBody Map<String, Object> map) {

		OrderMealPlanOnShowVo orderMealPlanOnShowVo = JSON.parseObject(JSON.toJSONString(map), OrderMealPlanOnShowVo.class);

		GetOrderPlanDishesRequest getOrderPlanDishesRequest =new GetOrderPlanDishesRequest();
		getOrderPlanDishesRequest.setComId(orderMealPlanOnShowVo.getUserInfo().getComId());
		getOrderPlanDishesRequest.setMealDate(orderMealPlanOnShowVo.getMealDate());
		getOrderPlanDishesRequest.setMealNo(orderMealPlanOnShowVo.getMealNo());
		getOrderPlanDishesRequest.setMerchId(0);
		getOrderPlanDishesRequest.setPointId(orderMealPlanOnShowVo.getPointId());
		getOrderPlanDishesRequest.setReceiptId(orderMealPlanOnShowVo.getReceiptId());
		Result result =  payConfigClientService.getOrderPlanDishes(getOrderPlanDishesRequest);
		log.info("返回排餐菜品列表 【{}】【{}】", map, result);
		return result;
	}

	/**
	 * 6.3点餐查询（OrderMealPlan/loadDishesClass）
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanLoadDishesClass)
	public Result loadDishesClass(@RequestBody Map<String, Object> map) {
		OrderMealPlanLoadDishesClassRequest request = JSON.parseObject(JSON.toJSONString(map), OrderMealPlanLoadDishesClassRequest.class);
		Result result = payConfigClientService.dishesClassList(request.getUserInfo().getComId(), request.getMerchId());
		log.info("返回排餐菜品分类 【{}】【{}】", map, result);
		return result;
	}




	/**
	 * 6.4提交点餐（OrderMealPlan/orderSubmit）
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanOrderSubmit)
	public Result orderSubmit(@RequestBody Map<String, Object> map) {
		OrderMealPlanSubmitRequest request = JSON.parseObject(JSON.toJSONString(map), OrderMealPlanSubmitRequest.class);

        if(request.getMealNo()==null){
            return ResultUtil.error(ResultEnum.Err_3117);
        }
		//计算金额  菜品是否还存在
//		Integer sum= request.getMealMenuInfo() .stream().collect(Collectors.summingInt(DishesInfoVo::getDishesPrice));
//		if(!request.getMealPrice().equals(sum)){
//			return ResultUtil.error(ResultEnum.Err_3081);
//		}

		//计算餐段时间
		if(request.getMealDate().equals(DateUtils.getDate())){
			ConsTimeConfigOnShowRequest consTimeConfigOnShowRequest =new ConsTimeConfigOnShowRequest();
			consTimeConfigOnShowRequest.setComId(request.getUserInfo().getComId());
			consTimeConfigOnShowRequest.setPage(1);
			consTimeConfigOnShowRequest.setSize(50);
			Result result1 = payConfigClientService.GetMealTimeInfo(consTimeConfigOnShowRequest);
			if (result1.getCode() == 200) {
				JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(result1.getData()));

				List<GetMealTimeDto> list = JSON.parseArray(JSON.toJSONString(jsonObject.get("list")), GetMealTimeDto.class);

				for (GetMealTimeDto mealTimeDto : list) {
					if (ObjectUtil.isNotEmpty(request.getMealNo()) && mealTimeDto.getMealNo().equals(request.getMealNo().toString())) {
						long nowLong = new Date().getTime();

						//餐段时间
						Date after = null;
						try {
							after = DateUtils.getDate(DateUtils.getDate() + " " + mealTimeDto.getBeginTime(), "yyyy-MM-dd HH:mm:ss");
						} catch (ParseException e) {
							continue;
						}
						long afterLong = after.getTime() - (mealTimeDto.getBeforeHour() * 3600000);

						if (nowLong > afterLong) {
							return ResultUtil.error(ResultEnum.Err_4144);
						}
					}
					continue;
				}
			}
		}


//		URL_getXfUserInfo
		OrderDishesPayRequest orderDishesPayRequest =new OrderDishesPayRequest();

		String ord = RandomUtil.generateNumber(8);
		Date date= new Date();
		String orderTime = DateUtils.getStrDate(date,DateUtils.YYYYMMDDHHMMSS) ;
		String orderNo2 = ord+orderTime;
		orderNo2 = "DC" + NumConvertUtil.IntToHexStringNum(request.getUserInfo().getComId().intValue(),6) + orderNo2 ;

		orderDishesPayRequest.setComId(request.getUserInfo().getComId());
		orderDishesPayRequest.setMachNo(request.getUserInfo().getAppId());
		orderDishesPayRequest.setTradeNo(orderNo2);
		orderDishesPayRequest.setAmount(request.getMealPrice());
		orderDishesPayRequest.setType(request.getType());
		orderDishesPayRequest.setConsType(1);
		orderDishesPayRequest.setOpenId(request.getUserInfo().getOpenId());
		orderDishesPayRequest.setPId(request.getUserInfo().getPId());
		orderDishesPayRequest.setConsState(5);
		orderDishesPayRequest.setPayWay(request.getPayWay());
		orderDishesPayRequest.setPointId(request.getPointId() != null ? request.getPointId() : 0);
		orderDishesPayRequest.setReceiptId(request.getReceiptId());
		orderDishesPayRequest.setReceiptName(request.getReceiptName());
		orderDishesPayRequest.setMealDate(request.getMealDate());
		orderDishesPayRequest.setMealNo(request.getMealNo());
		orderDishesPayRequest.setDishesInfo(request.getMealMenuInfo());
		orderDishesPayRequest.setRemark(request.getRemark());
		orderDishesPayRequest.setReceiptPrice(request.getReceiptPrice());
		if(request.getType()==9){
			//查询是否有建行签约 无签约直接失败
			Result<List<EntityXfChannelInfo>> result2 = payConfigClientService.signList(request.getUserInfo().getComId(),7);
			if(result2.getData()==null || result2.getData().size()==0){
				return ResultUtil.error(ResultEnum.Err_3047);
			}
			Result<List<EntityCompanyConfig>> result3 = companyClientService.getCompanyConfig(request.getUserInfo().getComId(),"delayPay");
			log.info("读取到配置 【{}】",result3);
			if(result3.getData() !=null && result3.getData().size()>0
					&& result3.getData().get(0).getConfig().equals("true")){
				if(!request.getMealDate().equals(DateUtils.getDate())){
					orderDishesPayRequest.setDelayPay(true);
				}
			}
		}

		
		if (request.getType() != 9) {
			//4. mq延时查询
			Gson gson = new Gson();
			CheckVo checkVo = new CheckVo();
			checkVo.setMachNo(request.getUserInfo().getAppId());
			checkVo.setCompanyId(request.getUserInfo().getComId());
			checkVo.setOutTradeNo(orderNo2);
			activeQuiryProduct.sendDelayMessage(gson.toJson(checkVo));
		}
		log.info("发起订餐请求 3bs144pe   提交点餐 【{}】原始参数 【{}】",orderDishesPayRequest,request);
		orderDishesPayRequest.setReceiptPrice(request.getReceiptPrice());
		Result result = payHandleClientService.orderDishesPay(orderDishesPayRequest);
		if (request.getType() == 9 && result.getCode() == 200) {
			Map<String, Object> resmap = new HashMap<>();
			resmap.put("type", 4);
			return ResultUtil.info(200, result.getMsg(), resmap);
		} else {
			return result;
		}

	}

	/**
	 * 6.7点餐餐段查询（OrderMealPlan/getOrderPlanMeal）
	 */
//	@PostMapping(WxServiceUrl.URL_OrderMealPlanGetOrderPlanMeal)
	public Result getOrderPlanMeal(@RequestBody Map<String, Object> map) {

		UgcOrderedShowRequest request = JSON.parseObject(JSON.toJSONString(map), UgcOrderedShowRequest.class);

		log.info("公众号点餐查询 【{}】【{}】", map, request);

		String endDateStr = DateUtil.getStrDate(DateUtil.addDays(DateUtils.strToDate2(request.getMealDate()), request.getDays()), "yyyy-MM-dd");

		GetUserOrdered getUserOrdered = new GetUserOrdered();
		getUserOrdered.setComId(request.getUserInfo().getComId());
		getUserOrdered.setPId(request.getUserInfo().getPId());
		getUserOrdered.setBeginDate(request.getMealDate());
		getUserOrdered.setEndDate(endDateStr);
		Result result = xfRecodeClientService.getUserOrdered(getUserOrdered);

		log.info("公众号已订餐查询-返回 【{}】【{}】", getUserOrdered, result);

		List<OrderedMealVo> mealVos = JSON.parseArray(JSON.toJSONString(result.getData()), OrderedMealVo.class);

		//获取餐段
		Result result1 = payConfigClientService.getCompanyMealNo(request.getUserInfo().getComId());

		if (result1.getCode() != 200 || result1.getData() == null) {
			return ResultUtil.error(ResultEnum.Err_3082);
		}

		List<EntityXfMealInfo> mealInfos = JSON.parseArray(JSON.toJSONString(result1.getData()), EntityXfMealInfo.class);

		List<List<UgcOrderedMealVo>> resMap = new ArrayList<>();


		for (int i = 0; i < request.getDays(); i++) {
			String dateStr = DateUtil.getStrDate(DateUtil.addDays(DateUtils.strToDate2(request.getMealDate()), i), "yyyy-MM-dd");


			Date dateCu = DateUtils.strToDate2(dateStr);

			List<OrderPlanMealVo> orderPlanMealVos = null;

			// 获取当前时间


			if(dateCu.compareTo(DateUtils.strToDate2(DateUtil.getDate()))>=0){

				//插标签 TODO
				UserInfoVo userInfoVo = new UserInfoVo();
				GzhUserInfo userInfo = request.getUserInfo();
				userInfoVo.setComId(Long.valueOf(userInfo.getComId()));
				userInfoVo.setPId(userInfo.getPId().intValue());
				userInfoVo.setOnlyOne(true);
				Result result3 = humanClientService.PersonnelGetPersonInfo(userInfoVo);
				if (200 != result3.getCode()) {
					return result3;
				}
				EntityPersonnelInfo entityPersonnelInfo = JSON.parseObject(JSON.toJSONString(result3.getData()), EntityPersonnelInfo.class);

				GetOrderPlanMealRequest getOrderPlanMealRequest = new GetOrderPlanMealRequest();
				getOrderPlanMealRequest.setMealDate(dateStr);
				getOrderPlanMealRequest.setComId(request.getUserInfo().getComId());
				getOrderPlanMealRequest.setTagIds(entityPersonnelInfo.getPTags());
				Result result2 = payConfigClientService.getOrderPlanMeal(getOrderPlanMealRequest);
				if(result2.getData()!=null){
					orderPlanMealVos =JSON.parseArray(JSON.toJSONString(result2.getData()), OrderPlanMealVo.class);
				}
			}

			List<UgcOrderedMealVo> ugcOrderedMealVos = new ArrayList<>();

			for (EntityXfMealInfo entityXfMealInfo : mealInfos) {
				Integer currMealNo = Integer.valueOf(entityXfMealInfo.getMealNo());
				UgcOrderedMealVo ugcOrderedMealVo = new UgcOrderedMealVo();
				ugcOrderedMealVo.setMealDate(dateStr);
				ugcOrderedMealVo.setMealNo(currMealNo);
				ugcOrderedMealVo.setStatus(1);
				ugcOrderedMealVo.setStatusStr("未订");

				if(mealVos!=null && mealVos.size()>0){
					for (OrderedMealVo orderedMealVo : mealVos) {
						if (orderedMealVo.getMealDate().equals(dateStr)
								&& orderedMealVo.getMealNo().equals(currMealNo)
						) {
							ugcOrderedMealVo.setStatus(2);
							ugcOrderedMealVo.setStatusStr("已订");
							break;
						}
					}
				}
				if(!ugcOrderedMealVo.getStatus().equals(2)){
					if(orderPlanMealVos==null || orderPlanMealVos.size() == 0){
						ugcOrderedMealVo.setStatus(4);
						ugcOrderedMealVo.setStatusStr("————");
					}else{
						Boolean flag =false;
						for (OrderPlanMealVo orderPlanMealVo:orderPlanMealVos){
							if(orderPlanMealVo.getMealDate().equals(dateStr)
									&& orderPlanMealVo.getMealNo().equals(entityXfMealInfo.getMealNo())
							){
								ugcOrderedMealVo.setInfoIds(orderPlanMealVo.getInfoIds());
								flag=true;
								break;
							}
						}

						if(ugcOrderedMealVo.getStatus()!=2){
							if(flag){
								ugcOrderedMealVo.setStatus(3);
								ugcOrderedMealVo.setStatusStr("可订");
							}else{
								ugcOrderedMealVo.setStatus(4);
								ugcOrderedMealVo.setStatusStr("————");
							}
						}
					}
				}

				ugcOrderedMealVos.add(ugcOrderedMealVo);
			}
			resMap.add(ugcOrderedMealVos);
		}

		Map<String, Object> resMap2 = new HashMap<>();

		resMap2.put("list" ,resMap);
		resMap2.put("meal" ,mealInfos);

		log.info("公众号点餐查询-返回 【{}】【{}】", request, resMap2);

		return ResultUtil.success(resMap2);
	}


	/**
	 * 6.8就餐时间查询（OrderMealPlan/getMealTime）
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanGetMealTime)
	public Result getMealTime(@RequestBody ConsTimeConfigOnShowRequest request) {
		return ResultUtil.success(payConfigClientService.GetMealTimeInfo(request));
	}

	/**
	 * 6.9（点餐）餐厅列表（OrderMealPlan/loadRestaurants）
	 */
	@PostMapping(WxServiceUrl.Url_OrderMealPlanLoadRestaurants)
	public Result LoadRestaurants(@RequestBody Map<String, Object> map) {

		LoadRestaurantsRequest request = JSON.parseObject(JSON.toJSONString(map), LoadRestaurantsRequest.class);
		Long comId = request.getUserInfo().getComId();
		request.setComId(comId);

		String strPoints = "";
		if (null != request.getPointId() && 0 < request.getPointId()) {
			strPoints = String.valueOf(request.getPointId());
		}
		request.setStrPoints(strPoints);
		request.setPage(1);
		request.setSize(500);
		Result result = payConfigClientService.restaurantList(request);
		if (200 == result.getCode()) {
			try {
				List<EntityPointConfig> entityPointConfigs = JSON.parseArray(JSON.toJSONString(result.getData()), EntityPointConfig.class);
				ConsTimeConfigOnShowRequest consTimeConfigOnShowRequest = new ConsTimeConfigOnShowRequest();
				consTimeConfigOnShowRequest.setSize(5000);
				consTimeConfigOnShowRequest.setPage(1);
				consTimeConfigOnShowRequest.setComId(request.getComId());
				Result mealTimeResult = this.getMealTime(consTimeConfigOnShowRequest);
				if (200 == mealTimeResult.getCode() && null != mealTimeResult.getData()) {
					JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(mealTimeResult.getData()));

					List<EntityXfMealTime> list = JSON.parseArray(jsonObject.getJSONObject("data").getString("list"), EntityXfMealTime.class);
					Map<Integer, List<EntityXfMealTime>> listMap = list.stream().filter(e -> null != e && e.getPointId() != null).collect(Collectors.groupingBy(e -> e.getPointId()));

					for (EntityPointConfig entityPointConfig : entityPointConfigs) {
						entityPointConfig.setMealTimes(listMap.getOrDefault(entityPointConfig.getPointId(), listMap.get(0)));
					}
				}
				result = ResultUtil.success(entityPointConfigs);
			}catch (Exception e) {
				e.printStackTrace();
			}

		}
		return result;
	}

	@PostMapping(WxServiceUrl.Url_OrderMealPlanLoadLimiConfig)
	public Result loadLimitConfig(@RequestBody Map<String, Object> map){
		ConsumeLimitConfigOnShowRequest request = JSON.parseObject(JSON.toJSONString(map), ConsumeLimitConfigOnShowRequest.class);
		Long comId = request.getUserInfo().getComId();
		Long pId = request.getUserInfo().getPId();

		request.setComId(comId);

		request.setLimitField(6);
		Result consumeLimitConfig = payConfigClientService.getConsumeLimitConfig(request);
		if (200 == consumeLimitConfig.getCode()) {
			try {
				ReConsumeLimitVo reConsumeLimitVo = JSON.parseObject(JSON.toJSONString(consumeLimitConfig.getData()), ReConsumeLimitVo.class);

				Result xfAccount = payConfigClientService.GetXFAccount(comId, pId.intValue(), 0);

				if (200 == xfAccount.getCode()) {
					EntityXfAccountInfo entityXfAccountInfo = JSON.parseObject(JSON.toJSONString(xfAccount.getData()), EntityXfAccountInfo.class);
					List<EntityXfAccountType> accountType = reConsumeLimitVo.getAccountType().stream().filter(o -> (entityXfAccountInfo.getAccTypeId() == o.getAccTypeId())).collect(Collectors.toList());

					reConsumeLimitVo.setAccountType(accountType);

					List<LimitListVo> limitList = reConsumeLimitVo.getLimitList().stream().filter(o -> (request.getMealNo() == o.getMealNo() && 1 == o.getConsType())).collect(Collectors.toList());

					for (LimitListVo limitListVo : limitList) {
						List<InLimitConfigVo> filteredLimitConfigs = limitListVo.getLimitConfig().stream()
								.filter(o -> accountType.get(0).getAccTypeId() == o.getAccountType())
								.collect(Collectors.toList());

						limitListVo.setLimitConfig(filteredLimitConfigs);
					}

					reConsumeLimitVo.setLimitList(limitList);
				}
				consumeLimitConfig.setData(reConsumeLimitVo);
			}catch (Exception e) {
				e.printStackTrace();
			}
		}

		return consumeLimitConfig;
	}

	@PostMapping(WxServiceUrl.URL_addDishesToCart)
	public Result addDishesToCart(@RequestBody Map<String, Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(map.get("mealMenuInfo")));
		if(ObjectUtil.isEmpty(jsonArray)){
			return ResultUtil.error(ResultEnum.Err_900);
		}
		jsonArray.forEach(json->{
			JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(json));
			EntityXfShoppingCart request = JSON.parseObject(JSON.toJSONString(map), EntityXfShoppingCart.class);
			request.setComId(userInfo.getComId());
			request.setPId(userInfo.getPId().intValue());
			request.setDishesId(jsonObject.getInteger("dishesId"));
			request.setDishesName(jsonObject.getString("dishesName"));
			request.setPriceMode(jsonObject.getInteger("priceMode"));
			request.setDishesPrice(jsonObject.getInteger("dishesPrice"));
			request.setWeightNumber(jsonObject.getInteger("weightNumber"));
			request.setPhotoUrl(jsonObject.getString("photoUrl"));
			this.payConfigClientService.addDishesToCart(request);

		});

		return ResultUtil.success();
	}

	@PostMapping(WxServiceUrl.URL_removeDishesToCart)
	public Result removeDishesToCart(@RequestBody Map<String, Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		RemoveDishesToCartRequest request = JSON.parseObject(JSON.toJSONString(map),RemoveDishesToCartRequest.class);
		request.setComId(userInfo.getComId());
		request.setPId(userInfo.getPId().intValue());
		return this.payConfigClientService.removeDishesToCart(request);
	}

	@PostMapping(WxServiceUrl.URL_getDishesFormCart)
	public Result getDishesFormCart(@RequestBody Map<String,Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		GetDishesFormCartRequest request =  JSON.parseObject(JSON.toJSONString(map),GetDishesFormCartRequest.class);
		request.setComId(userInfo.getComId());
		request.setPId(userInfo.getPId().intValue());
		Result<List<GetDishesFormCartVo >> result = this.payConfigClientService.getDishesFormCart(request);
		GetMerchPointListRequest getPointDishesRequest = new GetMerchPointListRequest();
		getPointDishesRequest.setComId(userInfo.getComId());
		Result resultA = this.payConfigClientService.getMerchPointList(getPointDishesRequest);
		if(!resultA.getCode().equals(200)){
			return ResultUtil.success();
		}

		List<EntityMealPlan> entityMealPlans = JSON.parseArray(JSON.toJSONString(resultA.getData()),EntityMealPlan.class);
		if(ObjectUtil.isEmpty(entityMealPlans)){
			return ResultUtil.success();
		}

		Map<Integer,String> merchInfo = new HashMap<>();
		Map<Integer,String> pointInfo = new HashMap<>();
		entityMealPlans.forEach(entityMealPlan -> {
			merchInfo.put(entityMealPlan.getMerchId(),entityMealPlan.getMerchName());
			pointInfo.put(entityMealPlan.getPointId(),entityMealPlan.getPointName());
		});
		List<Date> dateList = new ArrayList<>();
		for (GetDishesFormCartVo getDishesFormCartVo:result.getData()){
			dateList.add(getDishesFormCartVo.getMealDate());
		}

		if(ObjectUtil.isEmpty(dateList)){
			dateList.add(new Date());
		}
		GetUserOrdered getUserOrdered = new GetUserOrdered();
		getUserOrdered.setComId(request.getComId());
		getUserOrdered.setPId(request.getPId().longValue());
		getUserOrdered.setBeginDate(cn.hutool.core.date.DateUtil.formatDate( Collections.min(dateList)));
		getUserOrdered.setEndDate(cn.hutool.core.date.DateUtil.formatDate( Collections.max(dateList)));

		Result resultUserOrdered = this.xfRecodeClientService.getUserOrdered(getUserOrdered);
//		if(resultUserOrdered.getCode() != 200){
//			return ResultUtil.success();
//		}
		List<OrderedMealVo> orderedMealVoList = JSON.parseArray(JSON.toJSONString(resultUserOrdered.getData()),OrderedMealVo.class);

		Map<String, DishesFormCartVo> dishesFormCartVoMap = new HashMap<>();
		result.getData().forEach(getDishesFormCartVo -> {
			String key = String.format("%s%s%s%s",getDishesFormCartVo.getMerchId(),getDishesFormCartVo.getPointId(), cn.hutool.core.date.DateUtil.format(getDishesFormCartVo.getMealDate(), DatePattern.PURE_DATE_FORMAT),getDishesFormCartVo.getMealNo());
			DishesFormCartVo dishesFormCartVo = dishesFormCartVoMap.get(key);
			if(ObjectUtil.isEmpty(dishesFormCartVo)){
				dishesFormCartVo = new DishesFormCartVo();
				dishesFormCartVo.setComId(getDishesFormCartVo.getComId());
				dishesFormCartVo.setPId(getDishesFormCartVo.getPId());
				dishesFormCartVo.setMerchId(getDishesFormCartVo.getMerchId());
				dishesFormCartVo.setMerchName(merchInfo.get(getDishesFormCartVo.getMerchId()));
				dishesFormCartVo.setPointId(getDishesFormCartVo.getPointId());
				dishesFormCartVo.setMealDate(getDishesFormCartVo.getMealDate());

				dishesFormCartVo.setMealNo(getDishesFormCartVo.getMealNo());
				dishesFormCartVo.setPointName(pointInfo.get(getDishesFormCartVo.getPointId()));

				int status = 1;
				for(OrderedMealVo orderedMealVo: orderedMealVoList){
					if(orderedMealVo.getMealDate().equals(cn.hutool.core.date.DateUtil.formatDate(getDishesFormCartVo.getMealDate())) && orderedMealVo.getMealNo().equals(getDishesFormCartVo.getMealNo())){
						dishesFormCartVo.setStatus("已订");
						status = 2;
						break;
					}
				}

				if(status != 2){
					dishesFormCartVo.setStatus("不可订");
					GetOrderPlanMealRequest getOrderPlanMealRequest = new GetOrderPlanMealRequest();
					getOrderPlanMealRequest.setComId(request.getComId());
					getOrderPlanMealRequest.setMealDate(cn.hutool.core.date.DateUtil.formatDate(getDishesFormCartVo.getMealDate()));
					Result<List<OrderPlanMealVo>> resultOrderPlanMeal =  this.payConfigClientService.getOrderPlanMeal(getOrderPlanMealRequest) ;
					if(resultOrderPlanMeal.getCode() == 200){
						for (OrderPlanMealVo orderPlanMealVo: resultOrderPlanMeal.getData()){
							if(orderPlanMealVo.getMealDate().equals(cn.hutool.core.date.DateUtil.formatDate(getDishesFormCartVo.getMealDate())) && orderPlanMealVo.getMealNo().equals(String.valueOf(getDishesFormCartVo.getMealNo()))){
								dishesFormCartVo.setStatus("可订");
							}
						}
					}

				}


				dishesFormCartVo.setMealMenuInfo(new ArrayList<>());
			}
			DishesFormCartVo.MealMenuInfo mealMenuInfo = Convert.convert(DishesFormCartVo.MealMenuInfo.class,getDishesFormCartVo);
			dishesFormCartVo.getMealMenuInfo().add(mealMenuInfo);
			dishesFormCartVoMap.put(key,dishesFormCartVo);
		});
		return ResultUtil.success(dishesFormCartVoMap.values());
	}

	@PostMapping(WxServiceUrl.URL_orderSubmitByCart)
	public Result orderSubmitByCart(@RequestBody Map<String,Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		//String ord = RandomUtil.generateNumber(8);
		String ord = RandomUtil.generateNumber(6);
//		String ord = "00000000";
		Date date= new Date();
		String orderTime = DateUtils.getStrDate(date,DateUtils.YYYYMMDDHHMMSS) ;
		String orderNo2 = ord+orderTime;
		String prefix = "CART";
		orderNo2 = prefix + NumConvertUtil.IntToHexStringNum(userInfo.getComId().intValue(),6) + orderNo2 ;
		ShoppingCartRequest shoppingCartRequest = JSON.parseObject(JSON.toJSONString(map),ShoppingCartRequest.class);
		shoppingCartRequest.setCompanyId(userInfo.getComId());
		shoppingCartRequest.setTradeNo(orderNo2);
		shoppingCartRequest.setPId(userInfo.getPId());
		shoppingCartRequest.setOpenId(userInfo.getOpenId());
		shoppingCartRequest.setList(shoppingCartRequest.getShoppingCart());
		return this.payHandleClientService.shoppingCartPay(shoppingCartRequest);
	}

	/**
	 *
	 * @param map
	 * @return
	 */
	@PostMapping(WxServiceUrl.URL_OrderMealPlanGetOrderPlanMeal)
	public Result getOrderPlanMealB(@RequestBody Map<String, Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		GetOrderPlanMealBRequest getOrderPlanMealBRequest = JSON.parseObject(JSON.toJSONString(map), GetOrderPlanMealBRequest.class);
		if(ObjectUtil.isEmpty(getOrderPlanMealBRequest.getDays())){
			getOrderPlanMealBRequest.setDays(7);
		}

		GetUserOrderedB getUserOrderedB = new GetUserOrderedB();
		getUserOrderedB.setBeginDate(getOrderPlanMealBRequest.getMealDate());
		getUserOrderedB.setEndDate(cn.hutool.core.date.DateUtil.offsetDay(getOrderPlanMealBRequest.getMealDate(),getOrderPlanMealBRequest.getDays()));
		getUserOrderedB.setPId(userInfo.getPId());
		getUserOrderedB.setComId(userInfo.getComId());
//		已订餐日期和餐段
		Result<List<OrderedMealBVo>> listResult = this.xfRecodeClientService.getUserOrderedB(getUserOrderedB);
//
		Result mealInfoResult = this.payConfigClientService.getMealNameInfo(userInfo.getComId(),null);
		if(mealInfoResult.getCode() != 200){
			return ResultUtil.success();
		}
		Map<String, Object> mealNameInfoData = JSON.parseObject(JSON.toJSONString(mealInfoResult.getData()), HashMap.class);
		List<EntityXfMealInfo> entityXfMealInfos = JSON.parseArray(JSON.toJSONString(mealNameInfoData.get("list")), EntityXfMealInfo.class);
		List<EntityXfMealInfo> entityXfMealInfoList = new ArrayList<>();
		List<List<UgcOrderedMealVo>> ugcOrderedMealList = new ArrayList<>();
		for (EntityXfMealInfo entityXfMealInfo: entityXfMealInfos){
			ConsTimeConfigOnShowRequest configOnShowRequest = new ConsTimeConfigOnShowRequest();
			configOnShowRequest.setComId(entityXfMealInfo.getComId().longValue());
			configOnShowRequest.setMealNo(entityXfMealInfo.getMealNo());
			configOnShowRequest.setPage(1);
			configOnShowRequest.setSize(10);
			Result resultMealTimeInfo = this.payConfigClientService.GetMealTimeInfo(configOnShowRequest);
			if(mealInfoResult.getCode() != 200){
				continue;
			}
			Map<String, Object> mealTimeInfoData = JSON.parseObject(JSON.toJSONString(resultMealTimeInfo.getData()), HashMap.class);
			List<GetMealTimeDto> getMealTimeDtos=  JSON.parseArray(JSON.toJSONString(mealTimeInfoData.get("list")), GetMealTimeDto.class);
			if(ObjectUtil.isNotEmpty(getMealTimeDtos)){
				GetMealTimeDto getMealTimeDto = getMealTimeDtos.get(0);
				if(getMealTimeDto.getAllowDays() !=null && getMealTimeDto.getAllowDays() < 0){
					continue;
				}
				entityXfMealInfoList.add(entityXfMealInfo);
			}
		}
		for (int day = 0;day < getOrderPlanMealBRequest.getDays();day++){
			List<UgcOrderedMealVo> ugcOrderedMealVos = new ArrayList<>();
			Date date = cn.hutool.core.date.DateUtil.offsetDay(getOrderPlanMealBRequest.getMealDate(),day);
			String dateStr = cn.hutool.core.date.DateUtil.formatDate(date);
			//插标签 TODO
			UserInfoVo userInfoVo = new UserInfoVo();
//			GzhUserInfo userInfo = request.getUserInfo();
			userInfoVo.setComId(Long.valueOf(userInfo.getComId()));
			userInfoVo.setPId(userInfo.getPId().intValue());
			userInfoVo.setOnlyOne(true);
			Result result3 = humanClientService.PersonnelGetPersonInfo(userInfoVo);
			if (200 != result3.getCode()) {
				return result3;
			}
			EntityPersonnelInfo entityPersonnelInfo = JSON.parseObject(JSON.toJSONString(result3.getData()), EntityPersonnelInfo.class);
//
			GetOrderPlanMealRequest getOrderPlanMealRequest = new GetOrderPlanMealRequest();
			getOrderPlanMealRequest.setComId(userInfo.getComId());
			getOrderPlanMealRequest.setMealDate(dateStr);
			getOrderPlanMealRequest.setPointId(getOrderPlanMealBRequest.getPointId());
			getOrderPlanMealRequest.setTagIds(entityPersonnelInfo.getPTags());
			//餐段查询
			Result<List<OrderPlanMealVo>> resultOrderPlanMeal =  this.payConfigClientService.getOrderPlanMeal(getOrderPlanMealRequest) ;

			for (EntityXfMealInfo entityXfMealInfo: entityXfMealInfoList){
				UgcOrderedMealVo ugcOrderedMealVo = new UgcOrderedMealVo();
				ugcOrderedMealVo.setMealDate(dateStr);
				ugcOrderedMealVo.setMealNo(Integer.valueOf(entityXfMealInfo.getMealNo()));
				ugcOrderedMealVo.setStatus(5);
				ugcOrderedMealVo.setStatusStr("不可订");


				for(OrderPlanMealVo orderPlanMealVo:resultOrderPlanMeal.getData()){
					if(dateStr.equals(orderPlanMealVo.getMealDate()) && orderPlanMealVo.getMealNo() .equals(entityXfMealInfo.getMealNo())){
						ugcOrderedMealVo.setStatus(1);
						ugcOrderedMealVo.setStatusStr("可定");
						break;
					}
				}


				for(OrderedMealBVo orderedMealBVo:listResult.getData()){
					if(orderedMealBVo.getMealDate().equals(date) && orderedMealBVo.getMealNo() .equals(Integer.valueOf(entityXfMealInfo.getMealNo()))){
						ugcOrderedMealVo.setOrderNo(orderedMealBVo.getOrderNo());
						if(orderedMealBVo.getConsState().equals(4)){
							ugcOrderedMealVo.setStatus(4);
							ugcOrderedMealVo.setStatusStr("已取");
							break;
						}

						if(orderedMealBVo.getConsState().equals(5)){

							if(ugcOrderedMealVo.getStatusStr().equals("可定")) {
								ugcOrderedMealVo.setStatus(2);
								ugcOrderedMealVo.setStatusStr("已定");
							}else {
								ugcOrderedMealVo.setStatus(3);
								ugcOrderedMealVo.setStatusStr("已定-截止");
							}

							break;
						}
					}
				}
				if(ObjectUtil.isNotEmpty(ugcOrderedMealVo)){
					ugcOrderedMealVos.add(ugcOrderedMealVo);
				}

			}
			if(ObjectUtil.isNotEmpty(ugcOrderedMealVos)){
				ugcOrderedMealList.add(ugcOrderedMealVos);
			}

		}
		Map<String, Object> resMap2 = new HashMap<>();
		resMap2.put("list" ,ugcOrderedMealList);
		resMap2.put("meal" ,entityXfMealInfoList);
//		resMap2.put("meal" ,entityXfMealInfos);
		return ResultUtil.success(resMap2);
	}

	@PostMapping(WxServiceUrl.URL_VideoPayList)
	public Result videoPayList(@RequestBody Map<String,Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		String month = map.get("month").toString();
		Date date = new Date();
		try {
			date = cn.hutool.core.date.DateUtil.parse(month,"yyyyMM");
		}catch (Exception ignored){

		}
		GetPerVideoListRequest getPerVideoListRequest = JSON.parseObject(JSON.toJSONString(map),GetPerVideoListRequest.class);
		getPerVideoListRequest.setComId(userInfo.getComId());
		getPerVideoListRequest.setPId(userInfo.getPId());
		getPerVideoListRequest.setMonth(date);
		return this.xfRecodeClientService.getPerVideoList(getPerVideoListRequest);
	}

	@PostMapping(WxServiceUrl.URL_getPLOrderPlanMeal)
	public Result getPLOrderPlanMeal(@RequestBody Map<String, Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		GetOrderPlanMealBRequest getOrderPlanMealBRequest = JSON.parseObject(JSON.toJSONString(map), GetOrderPlanMealBRequest.class);
		if(ObjectUtil.isEmpty(getOrderPlanMealBRequest.getDays())){
			getOrderPlanMealBRequest.setDays(7);
		}

		GetUserOrderedB getUserOrderedB = new GetUserOrderedB();
		getUserOrderedB.setBeginDate(getOrderPlanMealBRequest.getMealDate());
		getUserOrderedB.setEndDate(cn.hutool.core.date.DateUtil.offsetDay(getOrderPlanMealBRequest.getMealDate(),getOrderPlanMealBRequest.getDays()));
		getUserOrderedB.setPId(userInfo.getPId());
		getUserOrderedB.setComId(userInfo.getComId());
//		已订餐日期和餐段
		Result<List<OrderedMealBVo>> listResult = this.xfRecodeClientService.getUserOrderedB(getUserOrderedB);
//
		Result mealInfoResult = this.payConfigClientService.getMealNameInfo(userInfo.getComId(),null);
		if(mealInfoResult.getCode() != 200){
			return ResultUtil.success();
		}
		Map<String, Object> mealNameInfoData = JSON.parseObject(JSON.toJSONString(mealInfoResult.getData()), HashMap.class);
		List<EntityXfMealInfo> entityXfMealInfos = JSON.parseArray(JSON.toJSONString(mealNameInfoData.get("list")), EntityXfMealInfo.class);
		List<EntityXfMealInfo> entityXfMealInfoList = new ArrayList<>();
		List<List<UgcOrderedMealVo>> ugcOrderedMealList = new ArrayList<>();
		for (EntityXfMealInfo entityXfMealInfo: entityXfMealInfos){
			ConsTimeConfigOnShowRequest configOnShowRequest = new ConsTimeConfigOnShowRequest();
			configOnShowRequest.setComId(entityXfMealInfo.getComId().longValue());
			configOnShowRequest.setMealNo(entityXfMealInfo.getMealNo());
			configOnShowRequest.setPage(1);
			configOnShowRequest.setSize(10);
			Result resultMealTimeInfo = this.payConfigClientService.GetMealTimeInfo(configOnShowRequest);
			if(mealInfoResult.getCode() != 200){
				continue;
			}
			Map<String, Object> mealTimeInfoData = JSON.parseObject(JSON.toJSONString(resultMealTimeInfo.getData()), HashMap.class);
			List<GetMealTimeDto> getMealTimeDtos=  JSON.parseArray(JSON.toJSONString(mealTimeInfoData.get("list")), GetMealTimeDto.class);
			if(ObjectUtil.isNotEmpty(getMealTimeDtos)){
				GetMealTimeDto getMealTimeDto = getMealTimeDtos.get(0);
				if(getMealTimeDto.getAllowDays() < 0){
					continue;
				}
				entityXfMealInfoList.add(entityXfMealInfo);
			}
		}

		for (int day = 0;day < getOrderPlanMealBRequest.getDays();day++){
			List<UgcOrderedMealVo> ugcOrderedMealVos = new ArrayList<>();
			Date date = cn.hutool.core.date.DateUtil.offsetDay(getOrderPlanMealBRequest.getMealDate(),day);
			String dateStr = cn.hutool.core.date.DateUtil.formatDate(date);

			GetOrderPlanMealRequest getOrderPlanMealRequest = new GetOrderPlanMealRequest();
			getOrderPlanMealRequest.setComId(userInfo.getComId());
			getOrderPlanMealRequest.setMealDate(dateStr);
			//餐段查询
			Result<List<OrderPlanMealVo>> resultOrderPlanMeal =  this.payConfigClientService.getOrderPlanMeal(getOrderPlanMealRequest) ;

			for (EntityXfMealInfo entityXfMealInfo: entityXfMealInfoList){
				UgcOrderedMealVo ugcOrderedMealVo = new UgcOrderedMealVo();
				ugcOrderedMealVo.setMealDate(dateStr);
				ugcOrderedMealVo.setMealNo(Integer.valueOf(entityXfMealInfo.getMealNo()));
				ugcOrderedMealVo.setStatus(5);
				ugcOrderedMealVo.setStatusStr("不可订");


				for(OrderPlanMealVo orderPlanMealVo:resultOrderPlanMeal.getData()){
					if(dateStr.equals(orderPlanMealVo.getMealDate()) && orderPlanMealVo.getMealNo() .equals(entityXfMealInfo.getMealNo())){
						ugcOrderedMealVo.setStatus(1);
						ugcOrderedMealVo.setStatusStr("可定");

						//
						GetOrderPlanDishesRequest getOrderPlanDishesRequest = new GetOrderPlanDishesRequest();
						getOrderPlanDishesRequest.setComId(userInfo.getComId());
						getOrderPlanDishesRequest.setMealDate(orderPlanMealVo.getMealDate());
						getOrderPlanDishesRequest.setMealNo(Integer.parseInt(entityXfMealInfo.getMealNo()));
						Result  resultPlanDishs= this.payConfigClientService.getOrderPlanDishes(getOrderPlanDishesRequest);
						if(resultPlanDishs.getCode().equals(200)){
							List<GetOrderPlanDishesResponse> responseList = JSON.parseArray(JSON.toJSONString(resultPlanDishs.getData()),GetOrderPlanDishesResponse.class);
							if(ObjectUtil.isNotEmpty(responseList)){
								GetOrderPlanDishesResponse getOrderPlanDishesResponse = responseList.get(0);
								UgcOrderedMealVo.MealMenuInfo mealMenuInfo = Convert.convert(UgcOrderedMealVo.MealMenuInfo.class,getOrderPlanDishesResponse);
								if(ObjectUtil.isNotEmpty(getOrderPlanDishesResponse.getPriceList())){
									GetOrderPlanDishesResponse.Price price = getOrderPlanDishesResponse.getPriceList().get(0);
									mealMenuInfo.setPriceMode("20");
									mealMenuInfo.setDishesPrice(price.getDishesPrice());
									mealMenuInfo.setWeightNumber("1");
								}
								ugcOrderedMealVo.setMealMenuInfo(mealMenuInfo);
							}
						}
						break;
					}
				}


				for(OrderedMealBVo orderedMealBVo:listResult.getData()){
					if(orderedMealBVo.getMealDate().equals(date) && orderedMealBVo.getMealNo() .equals(Integer.valueOf(entityXfMealInfo.getMealNo()))){
						ugcOrderedMealVo.setOrderNo(orderedMealBVo.getOrderNo());
						if(orderedMealBVo.getConsState().equals(4)){
							ugcOrderedMealVo.setStatus(4);
							ugcOrderedMealVo.setStatusStr("已取");
							break;
						}

						if(orderedMealBVo.getConsState().equals(5)){

							if(ugcOrderedMealVo.getStatusStr().equals("可定")) {
								ugcOrderedMealVo.setStatus(2);
								ugcOrderedMealVo.setStatusStr("已定");
							}else {
								ugcOrderedMealVo.setStatus(3);
								ugcOrderedMealVo.setStatusStr("已定-截止");
							}

							break;
						}
					}
				}
				if(ObjectUtil.isNotEmpty(ugcOrderedMealVo)){
					ugcOrderedMealVos.add(ugcOrderedMealVo);
				}

			}
			if(ObjectUtil.isNotEmpty(ugcOrderedMealVos)){
				ugcOrderedMealList.add(ugcOrderedMealVos);
			}

		}
		Map<String, Object> resMap2 = new HashMap<>();
		resMap2.put("list" ,ugcOrderedMealList);
//		resMap2.put("meal" ,entityXfMealInfos);
		resMap2.put("meal" ,entityXfMealInfoList);
		return ResultUtil.success(resMap2);
	}

	@PostMapping(WxServiceUrl.URL_getChangeDishes)
	public Result getChangeDishesList(@RequestBody Map<String,Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		GetChangeDishesListRequest getChangeDishesListRequest = JSON.parseObject(JSON.toJSONString(map), GetChangeDishesListRequest.class);
		getChangeDishesListRequest.setComId(userInfo.getComId());
		return this.payConfigClientService.getChangeDishesList(getChangeDishesListRequest);
	}

	@PostMapping(WxServiceUrl.URL_orderChangeDishes)
	public Result orderChangeDishes(@RequestBody Map<String,Object> map){
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		String orderNo = String.valueOf(map.get("orderNo"));
		Integer dishesId = Integer.valueOf(String.valueOf(map.get("dishesId")));
		String dishesName = String.valueOf(map.get("dishesName"));
		GetRecordProcessRequest getRecordProcessRequest = new GetRecordProcessRequest();
		getRecordProcessRequest.setCompanyId(userInfo.getComId());
		getRecordProcessRequest.setTradeNo(orderNo);
		Result result = this.payHandleClientService.getRecordProcess(getRecordProcessRequest);
		if(result.getCode() == 200 && ObjectUtil.isNotEmpty(result.getData())){
			String json = JSON.toJSONString(result.getData());
			EntityXfRecordProcess entityXfRecordProcess = JSON.parseObject(json,EntityXfRecordProcess.class);
			if(entityXfRecordProcess.getIfRefund() > 0){
				return ResultUtil.error(ResultEnum.Err_4136);
			}
			GetOrderPlanMealRequest getOrderPlanMealRequest = new GetOrderPlanMealRequest();
			getOrderPlanMealRequest.setMealDate(cn.hutool.core.date.DateUtil.formatDate(entityXfRecordProcess.getMealDate()));
			getOrderPlanMealRequest.setPointId(entityXfRecordProcess.getPointId().intValue());
			getOrderPlanMealRequest.setComId(userInfo.getComId());
			Result resultA = this.payConfigClientService.getOrderPlanMeal(getOrderPlanMealRequest);
			if(resultA.getCode() == 200 && ObjectUtil.isEmpty(resultA.getData())){
				return ResultUtil.error(ResultEnum.Err_4139);
			}

			UpdateChangeDishesRequest updateChangeDishesRequest = new UpdateChangeDishesRequest();
			updateChangeDishesRequest.setDishesName(dishesName);
			updateChangeDishesRequest.setDishesId(dishesId);
			updateChangeDishesRequest.setMonth(entityXfRecordProcess.getMonthValue());
			updateChangeDishesRequest.setOrderNo(entityXfRecordProcess.getOrderNo());
			updateChangeDishesRequest.setComId(entityXfRecordProcess.getComId());
			this.xfRecodeClientService.updateChangeDishes(updateChangeDishesRequest);

		}
		return ResultUtil.success();
	}
}
